package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.base.BaseRecycleViewAdapter;
import com.xkstream.client.entity.ReceiveGift;
import com.xkstream.client.view.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xiaoyi on 2017-9-29.
 */

public class ContributionRankAdapter extends BaseRecycleViewAdapter {
    List<ReceiveGift> mDatas;


    public ContributionRankAdapter(Context mContext, List<ReceiveGift> mDatas) {
        super(mContext);
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.layout_contribution_rank_item, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        onBindItem((ItemHolder) holder, position);
    }

    private void onBindItem(ItemHolder holder, int pos) {
        ReceiveGift data = mDatas.get(pos);
        holder.tvRank.setTextColor(pos < 3 ? mContext.getResources().getColor(R.color.money_selected)
                : mContext.getResources().getColor(R.color.text_title));
        holder.tvRankNum.setTextColor(pos < 3 ? mContext.getResources().getColor(R.color.money_selected)
                : mContext.getResources().getColor(R.color.text_title));
        holder.tvNickname.setText(data.getNickname());
        holder.tvRankNum.setText(String.valueOf(pos + 1));
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ivHeader)
        CircleImageView ivHeader;
        @BindView(R.id.tvNickname)
        TextView tvNickname;
        @BindView(R.id.tvRank)
        TextView tvRank;
        @BindView(R.id.tvRankNum)
        TextView tvRankNum;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
